package zhangcy.day0110;

import zhangcy.day0109.carlottery.dao.UserDao;
import zhangcy.day0109.carlottery.dao.impl.UserDaoImpl;
import zhangcy.day0109.carlottery.po.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
public class JstlDemoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        设置中文字符乱码，解决request/response响应
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
//        1、使用多态体现，实例化UserDao userDao数据访问层
        UserDao userDao = new UserDaoImpl();
//        2、创建map集合对象，用来存储查询列表的搜索条件参数
        Map<String, Object> map = new HashMap<>();
//        3、调用查询数据列表方法
        List<User> userList = userDao.queryUserBy(map);
        request.setAttribute("userList", userList);
//        转发jstl_demo.jsp页面
        request.getRequestDispatcher("jsp/zhangcy/day0110/jstl_demo.jsp").forward(request, response);
    }
}
